package com.example.library_common.db

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.library_common.global.AppGlobals

@Database(entities = [User::class,ShopCarBean::class], version = 1)
abstract class UserDatabase : RoomDatabase() {

    companion object {
        @Volatile
        private var DATA_BASE: UserDatabase? = null

        fun getInstance() = DATA_BASE ?: synchronized(this) {
            DATA_BASE ?: buildDataBase().also { DATA_BASE = it }
        }

        private fun buildDataBase() = Room.databaseBuilder(
            AppGlobals.getApplication(),
            UserDatabase::class.java,
            "UserInfoLab"
        ).allowMainThreadQueries()
            .build()

    }

    abstract fun userDao():UserDao

    abstract fun shopCarBean():ShoppingCarDao
}